package org.dromara.answerFront.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.answer.domain.bo.AiUserAnswersBo;
import org.dromara.answer.domain.bo.AiUserExamsBo;
import org.dromara.answer.domain.vo.AiUserAnswersVo;
import org.dromara.answer.domain.vo.AiUserExamsVo;
import org.dromara.answer.service.IAiUserExamsService;
import org.dromara.answerFront.service.IFrontUserExamsService;
import org.dromara.answerFront.vo.ComputationResultVo;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户考试记录
 *
 * @author Lion Li
 * @date 2025-04-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/answer/userExams")
public class FrontUserExamsController extends BaseController {

    private final IFrontUserExamsService userExamsService;

    /**
     * 用户查询自己的考试记录列表
     */
    @GetMapping("/list")
    public R<List<AiUserExamsVo>> list(AiUserExamsBo bo) {
        return R.ok(userExamsService.queryList(bo));
    }

    /**
     * 用户查询自己的考试记录详细信息
     *
     * @param userExamId 考试记录ID
     */
    @GetMapping("/{userExamId}")
    public R<AiUserExamsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long userExamId) {
        return R.ok(userExamsService.queryById(userExamId));
    }

    /**
     * 用户查询自己的考试记录详细信息
     *
     * @param userExamId 考试记录ID
     */
    @GetMapping("/byId")
    public R<AiUserExamsVo> byId(@NotNull(message = "主键不能为空")
                                    @RequestParam Long userExamId) {
        return R.ok(userExamsService.queryById(userExamId));
    }

    /**
     * 开始考试
     */
    @RepeatSubmit(interval = 1000)
    @PostMapping("/start")
    public R<AiUserExamsBo> start(@Validated(AddGroup.class) @RequestBody AiUserExamsBo bo) {
        return R.ok(userExamsService.start(bo));
    }

    /**
     * 提交试卷
     */
    @RepeatSubmit()
    @PostMapping("/submit")
    public R<AiUserExamsVo> submit(@Validated(EditGroup.class) @RequestBody AiUserExamsBo bo) {
        return R.ok(userExamsService.submit(bo));
    }

    /**
     * 选择题目
     */
    @PostMapping("/selectAnswer")
    public R<AiUserAnswersBo> selectAnswer(@Validated(EditGroup.class) @RequestBody AiUserAnswersBo bo) {
        return R.ok(userExamsService.selectAnswer(bo));
    }

}
